load("@build_bazel_rules_android//android:rules.bzl", "android_library")
load("//tools:gen_maven_jar_rules.bzl", "gen_maven_jar_rules")
load("//tools:jar_jar.bzl", "jar_jar")

package(default_visibility = ["//:__subpackages__"])

licenses(["notice"])

full_proto_deps = [
    "//proto:aes_cmac_java_proto",
    "//proto:aes_ctr_hmac_aead_java_proto",
    "//proto:aes_ctr_hmac_streaming_java_proto",
    "//proto:aes_ctr_java_proto",
    "//proto:aes_eax_java_proto",
    "//proto:aes_gcm_hkdf_streaming_java_proto",
    "//proto:aes_gcm_java_proto",
    "//proto:aes_siv_java_proto",
    "//proto:chacha20_poly1305_java_proto",
    "//proto:common_java_proto",
    "//proto:config_java_proto",
    "//proto:empty_java_proto",
    "//proto:ecdsa_java_proto",
    "//proto:rsa_ssa_pkcs1_java_proto",
    "//proto:rsa_ssa_pss_java_proto",
    "//proto:ecies_aead_hkdf_java_proto",
    "//proto:ed25519_java_proto",
    "//proto:hkdf_prf_java_proto",
    "//proto:hmac_java_proto",
    "//proto:kms_aead_java_proto",
    "//proto:kms_envelope_java_proto",
    "//proto:tink_java_proto",
    "//proto:xchacha20_poly1305_java_proto",
]

lite_proto_deps = [
    "//proto:aes_cmac_java_proto_lite",
    "//proto:aes_ctr_hmac_aead_java_proto_lite",
    "//proto:aes_ctr_hmac_streaming_java_proto_lite",
    "//proto:aes_ctr_java_proto_lite",
    "//proto:aes_eax_java_proto_lite",
    "//proto:aes_gcm_hkdf_streaming_java_proto_lite",
    "//proto:aes_gcm_java_proto_lite",
    "//proto:aes_siv_java_proto_lite",
    "//proto:chacha20_poly1305_java_proto_lite",
    "//proto:common_java_proto_lite",
    "//proto:config_java_proto_lite",
    "//proto:empty_java_proto_lite",
    "//proto:ecdsa_java_proto_lite",
    "//proto:rsa_ssa_pkcs1_java_proto_lite",
    "//proto:rsa_ssa_pss_java_proto_lite",
    "//proto:ecies_aead_hkdf_java_proto_lite",
    "//proto:ed25519_java_proto_lite",
    "//proto:hkdf_prf_java_proto_lite",
    "//proto:hmac_java_proto_lite",
    "//proto:kms_aead_java_proto_lite",
    "//proto:kms_envelope_java_proto_lite",
    "//proto:tink_java_proto_lite",
    "//proto:xchacha20_poly1305_java_proto_lite",
]

subtle_deps = [
    "//src/main/java/com/google/crypto/tink:primitives",
    "//src/main/java/com/google/crypto/tink/subtle",
    "//src/main/java/com/google/crypto/tink/subtle:aead",
    "//src/main/java/com/google/crypto/tink/subtle:daead",
    "//src/main/java/com/google/crypto/tink/subtle:hybrid",
    "//src/main/java/com/google/crypto/tink/subtle:keywrap",
    "//src/main/java/com/google/crypto/tink/subtle:mac",
    "//src/main/java/com/google/crypto/tink/subtle:signature",
    "//src/main/java/com/google/crypto/tink/subtle:streaming",
    "//src/main/java/com/google/crypto/tink/subtle:x25519",
    "//src/main/java/com/google/crypto/tink/subtle/prf",
]

java_deps = [
    "//src/main/java/com/google/crypto/tink",
    "//src/main/java/com/google/crypto/tink/aead",
    "//src/main/java/com/google/crypto/tink/config",
    "//src/main/java/com/google/crypto/tink/daead",
    "//src/main/java/com/google/crypto/tink/hybrid",
    "//src/main/java/com/google/crypto/tink/mac",
    "//src/main/java/com/google/crypto/tink/signature",
    "//src/main/java/com/google/crypto/tink/streamingaead",
    "//src/main/java/com/google/crypto/tink/util",
]

android_deps = [
    "//src/main/java/com/google/crypto/tink:android",
    "//src/main/java/com/google/crypto/tink/aead:android",
    "//src/main/java/com/google/crypto/tink/config:android",
    "//src/main/java/com/google/crypto/tink/daead:android",
    "//src/main/java/com/google/crypto/tink/hybrid:android",
    "//src/main/java/com/google/crypto/tink/integration/android",
    "//src/main/java/com/google/crypto/tink/mac:android",
    "//src/main/java/com/google/crypto/tink/signature:android",
    "//src/main/java/com/google/crypto/tink/streamingaead:android",
]

cleartext_deps = [
    "//src/main/java/com/google/crypto/tink:cleartext_keyset_handle",
]

cleartext_android_deps = [
    "//src/main/java/com/google/crypto/tink:cleartext_keyset_handle_android",
]

# PUBLIC

java_library(
    name = "java",
    visibility = ["//visibility:public"],
    exports = java_deps,
)

java_library(
    name = "awskms",
    visibility = ["//visibility:public"],
    exports = [
        "//src/main/java/com/google/crypto/tink/integration/awskms",
    ],
)

java_library(
    name = "gcpkms",
    visibility = ["//visibility:public"],
    exports = [
        "//src/main/java/com/google/crypto/tink/integration/gcpkms",
    ],
)

java_library(
    name = "cleartext_keyset_handle",
    visibility = ["//visibility:public"],
    exports = cleartext_deps,
)

java_library(
    name = "subtle",
    visibility = ["//visibility:public"],
    exports = subtle_deps,
)

# like :java, but for Android
android_library(
    name = "android",
    visibility = ["//visibility:public"],
    exports = android_deps,
)

java_library(
    name = "cleartext_keyset_handle_android",
    visibility = ["//visibility:public"],
    exports = cleartext_android_deps,
)

# RESTRICTED

java_library(
    name = "protos",
    exports = full_proto_deps,
)

java_library(
    name = "protos_android",
    exports = lite_proto_deps,
)

# Maven jars

gen_maven_jar_rules(
    name = "tink",
    doctitle = "Tink Cryptography API",
    deps = full_proto_deps + java_deps + cleartext_deps + subtle_deps,
)

gen_maven_jar_rules(
    name = "tink-awskms",
    doctitle = "Tink Cryptography API with AWS KMS",
    deps = [
        "//src/main/java/com/google/crypto/tink/integration/awskms",
    ],
)

gen_maven_jar_rules(
    name = "tink-gcpkms",
    doctitle = "Tink Cryptography API with Google Cloud KMS",
    deps = [
        "//src/main/java/com/google/crypto/tink/integration/gcpkms",
    ],
)

gen_maven_jar_rules(
    name = "tink-android",
    doctitle = "Tink Cryptography API for Android",
    deps = lite_proto_deps + android_deps + cleartext_android_deps + subtle_deps,
)

# Shading com.google.protobuf classes.
jar_jar(
    name = "tink-android-shaded",
    input_jar = ":tink-android",
    rules = "jar_jar_rules.txt",
)

# TEST

java_library(
    name = "testonly",
    testonly = 1,
    visibility = [
        "//visibility:public",
    ],
    exports = [
        ":cleartext_keyset_handle",
        ":java",
        ":protos",
        ":subtle",
    ],
)

android_library(
    name = "testonly_android",
    testonly = 1,
    visibility = ["//visibility:public"],
    exports = [
        ":android",
        ":cleartext_keyset_handle_android",
        ":protos_android",
        ":subtle",
    ],
)

java_library(
    name = "testutil",
    testonly = 1,
    visibility = ["//visibility:public"],
    exports = ["//src/main/java/com/google/crypto/tink/testing:test_util"],
)
